package com.longxi.tianjintianbao.ui.fragment.patrol;

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.ui.activity.patrol.PatrolListActivity;
import com.longxi.tianjintianbao.ui.base.LazyFragment;
import com.longxi.tianjintianbao.ui.presenter.patrol.PatrolListFgPresenter;
import com.longxi.tianjintianbao.ui.view.patrol.IPatrolListFgView;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;

public class PatrolListFragment extends LazyFragment<IPatrolListFgView, PatrolListFgPresenter> implements IPatrolListFgView {

    private String state = "-1";

    private int page = 0;

    @Override
    protected int provideContentViewId() {
        return R.layout.include_general_refresh_list;
    }

    @Override
    protected void init(View view) {
        state = getArguments().getString("state");
        //初始化View
        initView();
        if("3".equals(state)){
            mPresenter.initAdapter("0");
        }else{
            mPresenter.initAdapter(state);
        }
        //初始化数据
        initData();
    }

    public void initView(){

    }

    @Override
    protected PatrolListFgPresenter createPresenter() {
        return new PatrolListFgPresenter((PatrolListActivity) getActivity(), this);
    }

    private void initData() {

        mRefreshLayout.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {

            @Override
            public void onRefresh(RefreshLayout refreshLayout) {
                mPresenter.gjstatejz(page = 0, state);
            }

            @Override
            public void onLoadMore(RefreshLayout refreshLayout) {
                page++;
                mPresenter.getData(page, state);
            }
        });
        mPresenter.getInspectionList(page = 0, state);
    }

    public PatrolListFragment setArguments(String state) {
        Bundle bundle = new Bundle();
        bundle.putString("state", state);
        setArguments(bundle);
        return this;
    }

    @Override
    public SmartRefreshLayout getRefreshLayout() {
        return mRefreshLayout;
    }

    @Override
    public RecyclerView getRvContent() {
        return mRvContent;
    }

    public void refreshReceiptList() {
        if(mPresenter != null){
            mPresenter.gjstatejz(page = 0, state);
        }
    }

    @Override
    public void onDestroy() {
        mPresenter.onDestroy();
        super.onDestroy();
    }
}
